package com.jing.product.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.product.domain.dto.ProductAttributeDTO;
import com.jing.product.domain.vo.ProductAttributeVO;
import com.jing.product.service.ProductAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author：HaoYunde
 * @Package：com.jing.product.controller
 * @Project：Jing
 * @name：ProductAttributeController
 * @Date：2024/5/24 20:55
 */
@RestController
@RequestMapping("productAttribute")
@Validated
@Api(tags = "商品属性表")
public class ProductAttributeController extends BaseController {
    @Autowired
    private ProductAttributeService service;


    @GetMapping("findProductAttribute")
    @ApiOperation(value = "根据id查询商品属性表")
    public R findProductAttribute(@Valid @RequestParam Integer id,
                                  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        startPage();
        List<ProductAttributeVO> list = service.findProductAttribute(id);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    /**
     * 添加商品属性表
     * @param productAttributeDTO
     * @return
     */
    @PostMapping("add")
    @ApiOperation(value = "添加商品属性表")
    public R add(@RequestBody @Valid ProductAttributeDTO productAttributeDTO){
        service.add(productAttributeDTO);
        return R.ok("添加成功");
    }


    /**
     * 根据id查询商品参数表
     * @param id
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("findProductParm")
    @ApiOperation(value = "根据id查询商品参数表")
    public R findProductParm(@Valid @RequestParam Integer id,
                                  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        startPage();
        List<ProductAttributeVO> list = service.findProductParm(id);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    /**
     * 修改商品属性表
     * @param productAttributeDTO
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改商品属性表")
    public R update(@RequestBody @Valid ProductAttributeDTO productAttributeDTO){
        service.update(productAttributeDTO);
        return R.ok("修改成功");
    }


}
